package com.yny.administrator.android1607_meishi.thread;

import android.os.AsyncTask;

import com.handmark.pulltorefresh.library.PullToRefreshGridView;
import com.yny.administrator.android1607_meishi.bean.Movie;
import com.yny.administrator.android1607_meishi.utils.HttpUtils;

import org.json.JSONException;

import java.io.IOException;
import java.util.List;
/**
 * @author Administrator
 * 执行网络下载，返回json解析数据
 *
 */
public class LoadJsonTask extends AsyncTask<String,Void,List<Movie>> {
	public interface OnGetJsonListener{
		void getJsonListener(List<Movie> result);
	}
	private OnGetJsonListener mListener;
	private PullToRefreshGridView mGview;
	public LoadJsonTask(OnGetJsonListener listener,PullToRefreshGridView gview){
		this.mListener=listener;
		this.mGview=gview;
	}
	@Override
	protected List<Movie> doInBackground(String... params) {
		try {
			return HttpUtils.getJsonRes(params[0]);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	protected void onPostExecute(List<Movie> movies) {
		super.onPostExecute(movies);
		if (movies!=null){
			mListener.getJsonListener(movies);
			mGview.onRefreshComplete();
		}
	}
}
